# coding=utf-8
from appium import webdriver
from appium.options.android import UiAutomator2Options

from app_auto_po.basepage.basepage import BasePage
from app_auto_po.utils.log_util import logger


class WeWorkApp(BasePage):


    def start_app(self):
        logger.info("启动app")
        caps = {
            # 设置 app 测试的平台
            "platformName": "android",
            # 设置了使用的驱动
            "appium:automationName": "uiautomator2",
            # 设置被测设备名称
            "appium:deviceName": "127.0.0.1:7555",
            # 被测 app 包名
            "appium:appPackage": "com.tencent.wework",
            # 被测 app 启动页面的 Activity
            "appium:appActivity": ".launch.LaunchSplashActivity",
            # 不清空缓存
            "appium:noReset": True,
            # 每次初始化 driver 强制重启 app
            "appium:forceAppLaunch": True
        }
        self.driver = webdriver.Remote("http://localhost:4723",options = UiAutomator2Options().load_capabilities(caps))
        self.driver.implicitly_wait(10)
        # 返回本身的实例
        return self


    def stop_app(self):
        logger.info("关闭app")
        self.driver.quit()


    def main_page(self):
        logger.info("进入首页")
        from app_auto_po.page.main_page import MainPage
        return MainPage(self.driver)